//
//  PunchLittleView.swift
//  SwiftDemo
//
//  Created by 李文强 on 2017/1/10.
//  Copyright © 2017年 李文强. All rights reserved.
//

import UIKit

protocol PunchLittleViewDelegate {
    func getPuchName(name:String)
}

class PunchLittleView: UIView ,UITableViewDataSource,UITableViewDelegate{


    var delegate:PunchLittleViewDelegate?
    
    public var frandsArray:Array = [String]()
    public var specialFocusArray:Array = [String]()
    public var otherArray:Array = [String]()
    //声明数组
    let sectionArrat:[String] = ["我的朋友","特别关注","其他"]
    var tabelView: UITableView! = UITableView.init(frame: CGRect(x:0, y:0, width:120, height:200), style: UITableViewStyle.plain)
    
    func creatView() -> Void {
        
        self.frandsArray = ["Tom","Jim","Nice","Bryant"]
        self.specialFocusArray = ["Maria","Micial","jenif"]
        self.otherArray = ["Subscriptions"]
        
        self.tabelView.showsHorizontalScrollIndicator = false
        self.tabelView.showsVerticalScrollIndicator = false
        self.tabelView.frame = self.bounds
        self.tabelView.delegate = self
        self.tabelView.dataSource = self
        self.tabelView.backgroundColor = UIColor.clear
        self.addSubview(self.tabelView)
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        var str = String()
        switch indexPath.section {
        case 0:
            
            str = self.frandsArray[indexPath.row]
            break
          
        case 1:
            str = self.specialFocusArray[indexPath.row]
            break
          
        case 2:
            str = self.otherArray[indexPath.row]
            break
            
        default:
            break
            
        }
        self.delegate?.getPuchName(name: str)
    }
    //row
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if section == 0 {
            return self.frandsArray.count
        }else if section == 1{
            return self.specialFocusArray.count
        }else{
            return self.otherArray.count
        }
    }
    //section number
    func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }
    //row height
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 30
    }
    //cell header
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = UIView()
        let titleLible = UILabel()
        
        headerView.backgroundColor = UIColor.darkGray
        titleLible.font = UIFont.systemFont(ofSize: 13)
        titleLible.text = sectionArrat[section]
        titleLible.textColor = UIColor.black
        headerView.addSubview(titleLible)
        titleLible.mas_makeConstraints { (make:MASConstraintMaker?) in
            make!.left.equalTo()(headerView.mas_centerX)
            make!.right.equalTo()(10)
            make!.top.equalTo()(0)
            make!.bottom.equalTo()(0)
        }
        return headerView
    }
    //init cell
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell.init(style: UITableViewCellStyle.default, reuseIdentifier:
            "Cell")
        cell.backgroundColor = UIColor.darkGray
        cell.selectionStyle = UITableViewCellSelectionStyle.none
        switch indexPath.section {
        case 0:
            cell.textLabel?.text = self.frandsArray[indexPath.row]
            break
           
        case 1:
            cell.textLabel?.text = self.specialFocusArray[indexPath.row]
            break
           
        case 2:
            cell.textLabel?.text = self.otherArray[indexPath.row]
            break
           
        default:
            break
            
            
        }
        
        
        
        return cell
        
    }
    //header height
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 20
    }
//MARK:Create tabelView
    
    
}
